<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.apache.database.constant.Validator"%>
<%@page import="com.apache.passport.entity.Token"%>
<%@page import="com.apache.database.constant.SystemTools"%>
<%@page import="com.apache.passport.common.DesUtils"%>
<%@page import="com.apache.tools.StrUtil"%>
<%@page import="com.apache.passport.common.PassportHelper"%>

<%@ include file="/common/import.jsp"%>
<c:if test="${!empty loginUser }">
<% response.sendRedirect("index.action"); %>
</c:if>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>登陆成功  ||  欢迎登录中央认证系统</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <style>
  	.kk{
  		background-color: #ddffa9;
  		height: 100px;
  		width: auto;
  	}
  	.km{
  		padding-top: 10px;
  		padding-left: 50px;
  		float: left;
  	}
  	.ks{
  	padding-top: 20px;
  	padding-left: 130px;
  	}
  	.ks pm{
  		font-size: 20px;
  		color: #026804;
  	}
  	.ks tp{
  		font-size: 12px;
  		color: #026804;
  	}
  	
  
  </style>
  
  <script type="text/javascript">
  
  $(function() {
  //初始化界面优先加载上次用户登录信息
  	getLastMsg();
  });
  
  
  //右下角显示上次登录记录
 	 function getLastMsg(){
 	 	var outUrl = '${ctx}/passport/last/lastmsg.action';
	  		var mainPage = '${ctx}';
	  		$.ajax({
	  			url:outUrl,
	  			type:'post',
	  			success:function(data){
	  					var result = jQuery.parseJSON(data);
	  					var mst ='';
	  					if(result.userEname==undefined){
	  						mst='欢迎登录统一用户系统!';
	  					}else{
	  						mst+= '用户名:'+result.userEname;
		  					mst+='<br>上次登录IP:'+result.lgnLastipaddress;
		  					mst+='<br>上次登录系统:'+result.sysEname;
		  					mst+='<br>上次登录系统类型:'+result.lgnJudge;
		  					mst+='<br>上次登录系统版本:'+result.lgnLastdevice;
		  					mst+='<br>最后登录时间:'+result.lgnLasttime;
	  					}
				//显示上次用户登录记录	  					
	  					$.messager.show({
						title:'上次登录记录',
						msg:mst,
						timeout:5000,
						height:200,
						width:300,
						showType:'slide'
					});
	  			},
	  			error:function(data){
	  				alert("请检查服务器!");
	  			}
	  		});
		}


	//用户退出
  	function lgnout(){
  		$.messager.confirm('提示', '您确定工作已经保存,并退出该系统?', function(r){
	  		if (r){	
		  		var outUrl = '${ctx}/passport/logout/logout.action';
		  		var mainPage = '${ctx}';
			  		$.ajax({
			  			url:outUrl,
			  			type:'post',
			  			success:function(data){
			  				var result = jQuery.parseJSON(data);
			  				if (result.flag == 'T') {
								window.location.href = '${ctx}';
							} else {
								$.messager.alert('提交结果', result.msg, 'info');
							}
			  			},
			  			error:function(data){
			  				alert("请检查服务器!");
			  			}
			  		});
	  		}
  		});
  	}
  	
  </script>
  <body>
	   <div class="kk">
		   	<div class="km">
		   		<br><img src="${ctx}/images/confirm.gif">
		   	</div>
		   <div class="ks">
		   		<pm>登录成功!</pm><br>
		   		<tp>您已经成功登陆中央认证系统.</tp><br>
		   		<tp>出于安全考虑,一旦您访问过那些需要您提供凭证信息的应用时,请操作完成之后关闭浏览器.</tp>
		   		<tp><a href="javascript:lgnout();" >退出</a>
		   		<% 
		   			//判断当前用户是否有权限操作系统管理控制台
		   			String currCookie = PassportHelper.getInstance().getCurrCookie(request);
					Token token = (Token) SystemTools.getInstance().getCache("loginToken").getCacheCloneByKey(currCookie);
					if(token==null){
						token = (Token) SystemTools.getInstance().getCache("loginToken").getCacheCloneByKey(request.getParameter("tokenId"));
					}
					
					//2015年2月4日11:07:24 更新 如果客户端根据token访问获取
					if (StrUtil.isNull(currCookie)) {
						String pkt = request.getParameter("tokenId");
						if (!StrUtil.isNull(pkt)) {
							token = (Token) SystemTools.getInstance().getCache("loginToken").getCacheCloneByKey(pkt);
							Cookie cookie = null;
							cookie = new Cookie("dwu_", token.getTokenId());
							cookie.setPath("/");
							response.addCookie(cookie);
						}
					}
		   			String consoleUser = SystemTools.getInstance().getValue("console.user");
		   			Map<String,String> userMap = new HashMap<String,String>();
		   			String[] cosole = consoleUser.split(",");
		   			for(int i=0;i<cosole.length;i++){
		   				userMap.put(cosole[i],i+"");
		   			}
		   			String tokEname = token.getUserEname();
		   			if(!Validator.isNull(tokEname)){
		   				String userEname = DesUtils.getInstance().decrypt(tokEname);
		   				session.setAttribute("userEname",userEname);
		   				if(!Validator.isNull(userMap.get(userEname))){
		   					%>
		<a href="${ctx}/passport/ssosys/console.action" class="easyui-linkbutton" id="bt1" iconCls="icon-save">进入系统管理控制台</a>
		   					<% 
		   				}
		   			}
		   		 %>
		   		</tp>
		   </div>
	   </div>
	   <%@ include file="/common/bottom.jsp"%>
  </body>
</html>
